home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / include / sm_client.h
Encoding:
C/C++ Source or Header  |  1994-06-04  |  48.5 KB  |  1,822 lines

  1. #ifndef _SM_CLIENT_H_
  2. #define _SM_CLIENT_H_
  3. #include <stdio.h>
  4. #include <setjmp.h>
  5. #include <sys/types.h>
  6. #include <netinet/in.h>
  7. /* BEGIN visible to user */
  8.  
  9. /**********************************************************************
  10. * EXODUS Database Toolkit Software
  11. * Copyright (c) 1991 Computer Sciences Department, University of
  12. *                    Wisconsin -- Madison
  13. * All Rights Reserved.
  14. *
  15. * Permission to use, copy, modify and distribute this software and its
  16. * documentation is hereby granted, provided that both the copyright
  17. * notice and this permission notice appear in all copies of the
  18. * software, derivative works or modified versions, and any portions
  19. * thereof, and that both notices appear in supporting documentation.
  20. *
  21. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  22. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  23. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  24. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  25. *
  26. * The EXODUS Project Group requests users of this software to return 
  27. * any improvements or extensions that they make to:
  28. *
  29. *   EXODUS Project Group 
  30. *     c/o David J. DeWitt and Michael J. Carey
  31. *   Computer Sciences Department
  32. *   University of Wisconsin -- Madison
  33. *   Madison, WI 53706
  34. *
  35. *     or exodus@cs.wisc.edu
  36. *
  37. * In addition, the EXODUS Project Group requests that users grant the 
  38. * Computer Sciences Department rights to redistribute these changes.
  39. **********************************************************************/
  40.  
  41. /*
  42.  *    These values are used to define the assert
  43.  *    checking level of the compiled code
  44.  */
  45. #define LEVEL_1        1)
  46. #define LEVEL_2        2)
  47. #define LEVEL_3        3)
  48.  
  49.  
  50. #ifdef DEBUG
  51.  
  52. /*
  53.  *    This value control the level of assert
  54.  *    checking expansion for the current compile
  55.  */
  56. #define ASSERT_LEVEL        (3
  57.  
  58. #define MAGIC_CHECKING        ENABLED
  59.  
  60. #define OBJECT_MAGIC        DISABLED
  61.  
  62. #define LIST_CHECKING        ENABLED
  63.  
  64. #define PARAM_CHECKING        ENABLED
  65.  
  66. #define IO_STATISTICS        ENABLED
  67.  
  68.  
  69. #else
  70.  
  71.  
  72. /*
  73.  *    This value control the level of assert
  74.  *    checking expansion for the current compile
  75.  */
  76. #define ASSERT_LEVEL        (0
  77.  
  78. #define MAGIC_CHECKING    ENABLED
  79.  
  80. #define OBJECT_MAGIC        DISABLED
  81.  
  82. #define LIST_CHECKING        DISABLED
  83.  
  84. #define PARAM_CHECKING        DISABLED
  85.  
  86. #define IO_STATISTICS        ENABLED
  87.  
  88.  
  89. #endif
  90.  
  91. /* END visible to user */
  92. /* BEGIN visible to user */
  93.  
  94. #define SM_ASSERT(_level, _condition)                            \
  95.     if (ASSERT_LEVEL >= _level)    {                                \
  96.         if (!(_condition))    {                                    \
  97.             SM_Error(TYPE_FATAL, esmASSERT, __FILE__, __LINE__);\
  98.         }                                                        \
  99.     }
  100.  
  101. /* END visible to user */
  102. /* BEGIN visible to user */
  103.  
  104. /*
  105.  *    Turn on function prototypes for these compilers
  106.  */
  107. #if defined(_AIX) || defined(mips) || defined(__cplusplus) || defined(c_plusplus) || defined(__GNUC__)
  108. #    define PROTO(_parms) _parms 
  109. #else
  110.     /*
  111.      *    Turn it off for everything else
  112.      */
  113. #    define PROTO(_parms) ()
  114. #endif
  115.  
  116. #ifdef __cplusplus
  117. #define BEGIN_EXTERNC extern "C" {
  118. #define END_EXTERNC }
  119. #else
  120. #define BEGIN_EXTERNC 
  121. #define END_EXTERNC 
  122. #endif __cplusplus
  123.  
  124. /*
  125.  * Allow things to compile with c and c++ without having to 
  126.  * ifdef-out each use of "const"
  127.  */
  128. #ifndef __cplusplus
  129. #define const
  130. #endif
  131.  
  132. /*
  133.  * Some compilers do not know about volatile, including ATT C++.
  134.  * G++ seems to know about it.
  135.  * In order to avoid all sorts of warnings about the use
  136.  * of volatile in places like <sys/smp_lock.h> (for ultrix),
  137.  * and serverlib/include/queues.h.o, we define volatile out of
  138.  * existence for ATT C++.
  139.  */
  140. #if defined(__cplusplus) && !defined(__GNUC__)
  141. #define volatile
  142. #endif
  143.  
  144.  
  145. /*
  146.  * Boolean values.
  147.  */
  148. typedef char BOOL;
  149.  
  150. #ifndef TRUE
  151. #define TRUE    (1)
  152. #endif
  153. #ifndef FALSE
  154. #define FALSE    (0)
  155. #endif
  156.  
  157. /*
  158.  *    define some values for general macro expansion
  159.  */
  160. #define IS_ENABLED        ==1)
  161. #define IS_DISABLED        ==0)
  162. #define ENABLED            (1
  163. #define DISABLED        (0
  164.  
  165. /*
  166.  *    Universal constant for flags field
  167.  */
  168. #define NOFLAGS            ((FLAGS) 0)
  169.  
  170.  
  171. /*
  172.  * Machine dependent constants.
  173.  */
  174. #define    BYTESPERWORD    (sizeof(int))
  175. #ifndef BITSPERBYTE
  176. #    define    BITSPERBYTE        8
  177. #endif
  178. #define    BITSPERWORD        (BITSPERBYTE * BYTESPERWORD)
  179.  
  180.  
  181. /*
  182.  * Special "no error" error return.
  183.  */
  184. #define    esmNOERROR    0        /* non-error "error" code    */
  185. #define esmFAILURE    -1        /* standard failure call    */
  186.  
  187.  
  188. /*
  189.  * Invalid pointer values.
  190.  */
  191. #ifndef NULL
  192. #define    NULL        (VOID *)0    /* invalid memory address. Don't use this for int types; use ZERO */
  193. #endif
  194.  
  195. #define    ZERO        0
  196.  
  197. #define    NIL            -1        /* invalid integer index */
  198.  
  199.  
  200. /*
  201.  * Typedefs used all over.
  202.  */
  203. typedef char    ONE;            /* 1 byte */
  204. typedef short    TWO;            /* 2 bytes */
  205. typedef long    FOUR;            /* 4 bytes */
  206.  
  207.  
  208. typedef void    (*PFV)();        /* pointer to void function        */
  209. typedef int        (*PFI)();        /* pointer to integer function        */
  210. typedef char    *(*PFCP)();        /* pointer to char pointer function */
  211.  
  212. typedef unsigned char    UONE;    /* 1 byte */
  213. typedef unsigned short    UTWO;    /* 2 bytes */
  214. typedef unsigned long    UFOUR;    /* 4 bytes */
  215.  
  216. #ifndef _AIX
  217. typedef unsigned long    ulong;
  218. #endif
  219.  
  220. typedef unsigned int    FLAGS;
  221. typedef unsigned long    MAGIC;
  222. typedef unsigned short    SHORT_MAGIC;
  223.  
  224. /*
  225.  * These typedefs go here because they are used all over the place.
  226.  * They are variants of flags but are given different types to
  227.  * help avoid conflicts.
  228.  */
  229. typedef    FLAGS    BFFLAGS;
  230. typedef    FLAGS    SCANFLAGS;
  231. typedef    FLAGS    SCANTYPE;
  232. typedef    FLAGS    NEIGHBORFLAGS;
  233.  
  234.  
  235. /*
  236.  * Version history graph node id.
  237.  */
  238. typedef FOUR VHGNODEID;
  239.  
  240. /*
  241.  *  define a type for a slotted page slot
  242.  */
  243. typedef TWO     SLOTINDEX;
  244.  
  245. /*
  246.  * Macro for checking errors.
  247.  */
  248. #define    CHECKERROR(a)                             \
  249.         if ((int)(a) < smNOERROR) return ((int)(a))
  250.  
  251. /* END visible to user */
  252. /* BEGIN visible to user */
  253.  
  254. /*
  255.  *    Set object alignment to 8 byte bountries.
  256.  *
  257.  *    The only valid values are 8 and 4.  Adding new values
  258.  *    requires a change to include/object.h.
  259.  */
  260. #define ALIGNON 8
  261. #define ALIGNON1 (ALIGNON-1)
  262.  
  263. /*
  264.  *    the object size align macro
  265.  *
  266.  *    This macro aligns object sizes to ALIGNON boundries.
  267.  *    Note that zero length objects are also rounded up.
  268.  */
  269. #define ALIGNSIZE(_size)                                \
  270.     ( ((_size) == 0) ? ALIGNON :( (_size) + ALIGNON1 ) & ~ALIGNON1)
  271.  
  272.  
  273. /* END visible to user */
  274. /* BEGIN visible to user */
  275.  
  276. /*
  277.  *    definitions for communication between the client and the server process
  278.  */
  279. #define ERROR_REPLY             0     /* reply from server to client,
  280.                                  * when server cannot even tell what
  281.                                  * kind of message the client tried to
  282.                                  * send.
  283.                                  */
  284. #define MOUNT_VOLUME         1
  285. #define DISMOUNT_VOLUME         2
  286. #define FORMAT_VOLUME         3
  287. #define READ_PAGE             4
  288. #define WRITE_PAGE             5
  289. #define ALLOC_PAGE             6
  290. #define DEALLOC_PAGE         7
  291. #define CHECK_PAGE             8
  292. #define GET_UNIQUE             9
  293. #define STAT_VOLUME            10        
  294. #define SET_ROOT_ENTRY        11
  295. #define GET_ROOT_ENTRY        12
  296. #define REMOVE_ROOT_ENTRY    13
  297. #define BEGIN_TRANS            14
  298. #define COMMIT_TRANS        15
  299. #define ABORT_TRANS            16
  300. #define LOCK_PAGE            17
  301. #define LOCK_FILE            18
  302. #define CREATE_FILE            19
  303. #define DELETE_FILE            20    
  304. #define FIRST_PHYSICAL_PAGE    21    
  305. #define LAST_PHYSICAL_PAGE    22    
  306. #define NEIGHBOR_PAGE        23    
  307. #define FIRST_LOGICAL_PAGE    24    
  308. #define LAST_LOGICAL_PAGE    25    
  309. #define MARK_FILE_PAGE        26    
  310. #define RESET_RUSAGE        27    
  311. #define GET_RUSAGE            28    
  312. #define CREATE_SEQ_FILE        29
  313. #define OPEN_SEQ_LOAD        30
  314. #define OPEN_SEQ_SCAN        31
  315. #define SCAN_NEXT_SEQ        32
  316. #define LOAD_NEXT_SEQ        33
  317. #define CLOSE_RESOURCE        34
  318. #define TEST_NULL_RPC        35
  319. #define TEST_PAGE_RPC        36
  320.  
  321. #define WRITE_LOG_PAGE         37
  322. #define INIT_CLIENT            38
  323. #define UNLOCK_PAGE            39
  324. #define UNLOCK_FILE            40
  325. #define QUERY_PAGE            41
  326. #define SET_ANCHOR            42
  327. #define SET_CLR                43
  328. #define MON_DUMP            44
  329.  
  330. /*
  331.  * administrative messages    
  332.  */
  333. #define ADMIN_CHECKPOINT    45
  334. #define ADMIN_CHECKPOINTFREQ    46
  335. #define ADMIN_SHUTSERVER    47
  336. #define ADMIN_STATISTICS    48
  337. #define ADMIN_DEBUG            49
  338.     /* divided into these: */
  339. #define     ADMIN_DEBUG_CLIENT_LOG_OFF    500
  340. #define     ADMIN_DEBUG_SET_VAR            501
  341.  
  342. #define TEST_PAGE_SEND        50
  343. #define SYNC_TRANS            51
  344. #define FILE_NUMPAGES        52
  345.  
  346. /* 
  347.  *    distributed commit messages
  348.  */
  349. #define ENTER2PC            53
  350. #define COORD_PREPARE_TRANS    54
  351. #define COORD_VOTE_REQ        55
  352. #define SERVER_VOTE            56
  353. #define CLIENT_COMMAND        57 /* ?? do we need this or use COMMIT/ABORT */
  354. #define    CONTINUE_2PC        58
  355. #define RECOVER_2PC            59
  356.  
  357. #define COORD_COMMAND        60
  358. #define SERVER_ACK            61
  359.  
  360. #define ADD_VOLUME            62
  361. #define RM_VOLUME            63
  362.  
  363. #define MAX_MSG_NUMBER        63    
  364.  
  365. #define SENT        0x1
  366. #define RECEIVED    0x2
  367.  
  368. typedef struct {
  369.     char  *name;
  370.     short  type;
  371. } MESSAGENAME;
  372. extern MESSAGENAME    MsgNames[];
  373.  
  374. typedef struct msg_stats {
  375.     int    sent [ MAX_MSG_NUMBER+1 ];
  376.     int    received [ MAX_MSG_NUMBER+1 ];
  377.     int    replied_ok [ MAX_MSG_NUMBER+1 ];
  378.     int    replied_in_error [ MAX_MSG_NUMBER+1 ];
  379.     int    no_reply_requested [ MAX_MSG_NUMBER+1 ];
  380.     int    bytes_sent; 
  381.     int    bytes_received;
  382.     int    pages_sent; /* anything larger than MIN_PAGESIZE */
  383.     int pages_received; /* anything larger than MIN_PAGESIZE */
  384.     int    partial_pages_sent; /* anything smaller than MIN_PAGESIZE */
  385.     int partial_pages_received; /* anything smaller than MIN_PAGESIZE */
  386. } MESSAGESTATS;
  387.  
  388. extern MESSAGESTATS MsgStats;
  389.  
  390. /* END visible to user */
  391. /* BEGIN visible to user */
  392. /*
  393.  *    Typedef for volume id
  394.  */
  395. typedef TWO        VOLID;
  396.  
  397. /*
  398.  *  macro for finding the index into the buffer list
  399.  *  for the given size buffer
  400.  *  (Really a bf macro but it's used on both cli & srvr)
  401.  */
  402. #define OFFSET(_page2size)      (_page2size - MIN_PAGE2SIZE)
  403.  
  404. /*
  405.  *  define a force mark for the WAL protocol
  406.  */
  407. typedef FOUR                    FORCEMARK;
  408.  
  409. /*
  410.  * Short form of PID (no volume id)
  411.  */
  412. typedef FOUR    SHORTPID;
  413.  
  414.  
  415. /*
  416.  * Definition for page identifier (PID).
  417.  * Ifdefs allow an application to be compiled with C or C++.
  418.  */
  419. #if defined(__cplusplus) || defined(c_plusplus)
  420.  
  421. class PID {
  422. public:
  423.  
  424. #else 
  425.  
  426. struct PID {
  427.  
  428. #endif 
  429.  
  430.     SHORTPID     page;        /* page address */
  431.     VOLID         volid;        /* volume id */
  432.  
  433. #if defined(__cplusplus) || defined(c_plusplus)
  434.  
  435.     inline BOOL equalFunc(PID *other) const {
  436.         return ((other->page == this->page) &&
  437.             (other->volid == this->volid));
  438.     };
  439.     inline int hashFunc() const { return (int)(this->page); };
  440.  
  441. #if defined(SHELL_C)
  442.     operator char*();     /* used by tcl shell only */
  443.     void fill(char* s);
  444. #endif 
  445.  
  446. #endif 
  447.  
  448. }; /* } class PID */
  449.  
  450. /*
  451.  *    define the type of the unique field
  452.  */
  453. typedef UFOUR    UNIQUE;
  454.  
  455.  
  456. /* 
  457.  * Temporary typedef for file id.
  458.  */
  459. typedef struct {
  460.  
  461.     PID            pid;        /* the root page of the file    */
  462.     UNIQUE        unique;        /* unique bit for file            */
  463.  
  464. } FID;
  465.  
  466. /* END visible to user */
  467. /* BEGIN visible to user */
  468.  
  469. /*
  470.  *    define the log record counter
  471.  */
  472. typedef struct    {
  473.  
  474.     UFOUR    wrapCount;
  475.     UFOUR    count;
  476.  
  477. } LRC;
  478.  
  479. /* END visible to user */
  480. /* BEGIN visible to user */
  481.  
  482. /*
  483.  *    definitions for the buffer queues
  484.  */
  485. #define MIN_PAGE2SIZE        13 /*8K*/
  486. #define MIN_PAGESIZE        (1 << MIN_PAGE2SIZE)
  487. #define MAX_PAGE2SIZE        16
  488. #define MAX_PAGESIZE        (1 << MAX_PAGE2SIZE)
  489. #define MAX_BLOCK2_COUNT    (MAX_PAGE2SIZE - MIN_PAGE2SIZE)
  490. #define MAX_BLOCK_COUNT        (MAX_PAGESIZE/MIN_PAGESIZE)
  491.  
  492. #define BITMAP_PAGE2SIZE    (MIN_PAGE2SIZE)
  493. #define BITMAP_PAGESIZE        (1 << BITMAP_PAGE2SIZE)
  494. #define BITMAP_USABLESIZE    (BITMAP_PAGESIZE - sizeof(LRC))
  495.  
  496. #define HEADER_PAGE2SIZE    (MIN_PAGE2SIZE)
  497. #define HEADER_PAGESIZE        (MIN_PAGESIZE)
  498.  
  499. /* END visible to user */
  500. /* BEGIN visible to user */
  501. #define            VOL_PROPERTIES    0x5 /* all the flags that have any meaning below  */
  502. #define            VOLPROP_TEMP    0x1 /* cannot be temp and log */
  503. #define            VOLPROP_UNUSED    0x2 /* RAWDEV is not a permanent property */
  504. #define            VOLPROP_LOG        0x4 /* is a log (if not a log, its a data volume) */
  505. /* END visible to user */
  506. /* BEGIN visible to user */
  507. /*
  508.  *    define  the maximum that the root name can be
  509.  */
  510. #define MAX_ROOTNAME_SIZE    32
  511. #define MAX_ROOTDATA_SIZE    32
  512. /* END visible to user */
  513. /* BEGIN visible to user */
  514.  
  515. /*
  516.  *    object.h
  517.  *
  518.  *        defines, typedefs, etc. used by object-level routines and
  519.  *        clients of the storage manager.
  520.  */
  521.  
  522. /*
  523.  *    define the size of slotted pages
  524.  */
  525. #define SLOTTED_PAGE2SIZE    MIN_PAGE2SIZE
  526. #define SLOTTED_PAGESIZE    (1 << SLOTTED_PAGE2SIZE)
  527.  
  528.  
  529. /*
  530.  *    define the sizes of large object pages
  531.  */
  532. #define LG_PAGE2SIZE    MIN_PAGE2SIZE
  533. #define LG_PAGESIZE        (1 << LG_PAGE2SIZE)
  534. #if    (MIN_PAGE2SIZE == 12)
  535. #    define LGDATA_PAGE2SIZE    (MIN_PAGE2SIZE+1) /* double lg obj pages */
  536. #else
  537. #    define LGDATA_PAGE2SIZE    (MIN_PAGE2SIZE)   /* large obj pages == others */
  538. #endif
  539. #define LGDATA_PAGESIZE    (1 << LGDATA_PAGE2SIZE)
  540. /*#define LGDATA_USABLESIZE is defined below */
  541.  
  542.  
  543. /*
  544.  *    define the sizes of btree pages
  545.  */
  546. #define BTREE_PAGE2SIZE        MIN_PAGE2SIZE
  547. #define BTREE_PAGESIZE        (1 << BTREE_PAGE2SIZE)
  548. #define INDEXDESC_PAGE2SIZE    MIN_PAGE2SIZE
  549. #define INDEXDESC_PAGESIZE    (1 << INDEXDESC_PAGE2SIZE)
  550.  
  551. /*
  552.  *    define the number of uniques allocated when page is created
  553.  *    (100 per every 4K of pagesize)
  554.  */
  555. #if SLOTTED_PAGE2SIZE < 12
  556. #define UNIQUE_ALLOC_COUNT    (100)
  557. #else
  558. #define UNIQUE_ALLOC_COUNT    (100+100*(SLOTTED_PAGE2SIZE-12))
  559. #endif
  560.  
  561.     
  562. /*
  563.  *    Typedef for object addresses.
  564.  */
  565. typedef struct {
  566.  
  567.     SHORTPID    page;            /* the page address of the object's header    */
  568.     SLOTINDEX    slot;            /* slot number of the object                */
  569.     VOLID        volid;            /* the id of the volume                        */
  570.     UNIQUE        unique;            /* unique number of the object                */
  571.  
  572. } OBJADDR;
  573.  
  574.  
  575. /*
  576.  * Typedef for object ids.
  577.  */
  578. typedef struct {
  579.  
  580.     OBJADDR  diskAddr;            /* the object's disk address    */
  581.  
  582. } OID;
  583.  
  584.  
  585. /* END visible to user */
  586. /* BEGIN visible to user */
  587.  
  588. /*
  589.  *    Defines for near in CreateObject call.
  590.  */
  591. #define NEAR_OBJ              1
  592. #define NEAR_FIRST            2
  593. #define NEAR_LAST            3
  594. #define NEAR_DISTINGUISHED    4    /* not used */
  595. /* for backward compatibility */
  596. #define NEAR_FIRST_PHYSICAL    NEAR_FIRST
  597. #define NEAR_LAST_PHYSICAL    NEAR_LAST    
  598. #define NEAR_FIRST_LOGICAL    NEAR_FIRST
  599. #define NEAR_LAST_LOGICAL    NEAR_LAST
  600.  
  601.  
  602. /*
  603.  *    Typedef for generic object headers as viewed by clients of the storage manager.
  604.  *    Note that the fields must match the initial fields of SMALLOBJHDR 
  605.  *    and LARGEOBJHDR (all the same for now).
  606.  */
  607. typedef struct {
  608.  
  609.     TWO            properties;        /* the properties bit vector    */
  610.     TWO            tag;            /* the object's tag                */
  611.     FOUR        size;            /* the object's data size        */
  612.  
  613.     /* MUST MAINTAIN 8-byte ALIGNMENT HERE: if you change this 
  614.      * the size of the OBJHDR, you might have to add a filler
  615.      * to maintain 8-byte alignment e.g.
  616.         FOUR        filler;        
  617.      */
  618.  
  619. #if OBJECT_MAGIC IS_ENABLED
  620.     MAGIC        magic;
  621. #if (ALIGNON == 8)
  622.     FOUR        filler;        
  623.     /* no alignment needed */
  624. #elif (ALIGNON == 4)
  625.     /* no alignment needed */
  626. #else
  627.     not implemented
  628. #endif
  629. #endif OBJECT_MAGIC IS_ENABLED
  630.  
  631.  
  632. } OBJHDR;
  633.  
  634.  
  635. #define OBJECT_HDR_MAGIC        0x8AC429DA
  636.  
  637.  
  638. /* END visible to user */
  639. /* BEGIN visible to user */
  640. /*
  641.  *    Properties bits; only a few for now.
  642.  */
  643. #define P_LARGEOBJ        0x1        /* whether this is a large object        */
  644. #define P_HEADERONPAGE    0x2        /* large object header is on the page    */
  645. #define P_PAGESIZEOBJ    0x4        /* whether this is a page size object    */
  646. #define P_MOVED            0x8        /* object has been moved to a new page    */
  647. #define P_FORWARD        0x10    /* this is the forwarded record            */
  648. #define P_VERSIONED        0x20    /* object is versioned                   */
  649. #define P_FROZEN        0x40    /* object is frozen version             */
  650. #define P_HISTORYGRAPH    0x80    /* object is a version history graph */
  651. #define P_DESTROYPENDING    0x100    /* object is marked to be destroyed
  652.                                        pending freezing of all working i
  653.                                        verions */
  654. #define P_INDEX            0x200    /* object is an index                    */
  655. #define P_CREATEINPROGRESS    0x400    /* object is process of being created.
  656.                                         used for logging lg obj creates. */
  657.  
  658. /*
  659.  *    define a type for a slot that includes a unique number
  660.  */
  661. typedef struct {
  662.  
  663.     FOUR    offset;
  664.     UNIQUE    unique;
  665.  
  666. } PAGESLOT;
  667.  
  668.  
  669. /*
  670.  *    Define a header for the slotted page
  671.  */
  672. typedef struct {
  673.  
  674.     SLOTINDEX      slotCount;            /* slots in use on the page                */
  675.     SLOTINDEX    freeSlot;            /* list of free slots                    */
  676.     LRC            lrc;                /* lrc for logging                        */
  677.     FOUR         freeStart;            /* offset of contig free area on page    */
  678.     FOUR         freeBytes;            /* free bytes in the page                */
  679.     PID         pid;                /* the page's pid                        */
  680.     FID         fid;                /* the file the page belongs to            */
  681.     PID         neighborPid;        /* the neighboring page Pid                */
  682.     SHORTPID    nextLogicalPid;        /* used for logical sequence sets        */
  683.     FOUR        largeCount;            /* marked if the page has large obj        */
  684.     UNIQUE        unique;                /* current unique value                    */
  685.     FOUR        uniqueCount;        /* limit of unique values                */
  686.     MAGIC        magic;
  687.  
  688. } SLOTTEDHEADER;
  689.  
  690.  
  691. /*
  692.  *    Amount of contiguous free space initially on page.
  693.  */
  694. #define INITIALLYFREE    (SLOTTED_PAGESIZE - sizeof(SLOTTEDHEADER))
  695.  
  696. /*
  697.  *    the definition of a page
  698.  */
  699. typedef struct {
  700.  
  701.     char            data[INITIALLYFREE - sizeof(PAGESLOT)];    /* the data region    */
  702.     PAGESLOT        slot[1];            /* slot array, indexes backwards        */
  703.     SLOTTEDHEADER    header;                /* header of the slotted page            */
  704.  
  705. } SLOTTEDPAGE;
  706.  
  707.  
  708. #define SLOT_PAGE_MAGIC            0xb1a5dccb
  709.  
  710.  
  711. /* 
  712.  *    Maximum number of slots on a page.
  713.  */
  714. #define MAXPAGESLOTS    ((SLOTTED_PAGESIZE - sizeof(SLOTTEDHEADER)) / sizeof(PAGESLOT))
  715.  
  716.  
  717. /*
  718.  *    Define for the threshold at which a new object starts life as
  719.  *    a large object rather than a small object.  This must be defined
  720.  *    to include the size of the small object header.
  721.  */
  722. #ifdef LGTESTING
  723. #    define LARGETHRESHOLD    LGMAXLEAF
  724. #else
  725. #    define LARGETHRESHOLD    \
  726.         (SLOTTED_PAGESIZE - (sizeof(SLOTTEDHEADER) + sizeof(PAGESLOT) + sizeof(OBJHDR)))
  727. #endif
  728.  
  729.  
  730. /*
  731.  *    define the largest large object that will fit in a tree with
  732.  *    the root on a slotted page
  733.  */
  734. #define LSLOTTHRESHOLD        (LGMAXPAGESLOTS * LGMAXLEAF)
  735.  
  736.  
  737. /*
  738.  *    define some state variables for checking for free space
  739.  */
  740. #define PAGE_NO_SPACE        0x0
  741. #define PAGE_LAST_SLOT        0x1
  742. #define PAGE_INT_SLOT        0x2
  743.  
  744.  
  745. /*
  746.  *    define the hash function for hashing an oid
  747.  */
  748. #define BF_HashOid(_oid)                                \
  749.     ((_oid)->diskAddr.unique & ObjectHashMask)
  750.  
  751.  
  752.  
  753. #define INIT_LARGENODE_MAGIC(_nodePtr)                    \
  754.                                                         \
  755.     (_nodePtr)->header.magic = LARGENODE_MAGIC;            
  756.     
  757. #define INIT_LGDATAHDR_MAGIC(_nodePtr)                    \
  758.                                                         \
  759.     (_nodePtr)->header.magic = LGDATAHDR_MAGIC;            
  760.     
  761. #define INIT_SLOTROOT_MAGIC(_nodePtr)                    \
  762.                                                         \
  763.     (_nodePtr)->header.magic = SLOTROOT_MAGIC;            
  764.  
  765.     
  766. /*
  767.  *    define a check for a large node magic number
  768.  */
  769. #define CHECK_LARGENODE_MAGIC(_nodePtr)                    \
  770.                                                         \
  771.     if ((_nodePtr)->header.magic != LARGENODE_MAGIC)    {    \
  772.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  773.     }
  774.     
  775.  
  776. /*
  777.  *    define a check for a large data magic number
  778.  */
  779. #define CHECK_LGDATAHDR_MAGIC(_nodePtr)                    \
  780.                                                         \
  781.     if ((_nodePtr)->header.magic != LGDATAHDR_MAGIC)    {    \
  782.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  783.     }
  784.     
  785.  
  786. /*
  787.  *    define a check for a large node magic number
  788.  */
  789. #define CHECK_SLOTROOT_MAGIC(_nodePtr)                    \
  790.                                                         \
  791.     if ((_nodePtr)->header.magic != SLOTROOT_MAGIC)    {    \
  792.         SM_ERROR(TYPE_FATAL, esmINTERNAL);                \
  793.     }
  794.  
  795.  
  796. /*
  797.  *    define index descriptor stuff
  798.  */
  799.  
  800. #define SM_MAXELEMLEN   20      /* range 4--124 (multiples of 4) */
  801.  
  802. typedef enum { SM_BTREENDX, SM_HASHNDX } SMTYPE;
  803.  
  804. typedef enum { SM_EQ = 1, SM_G = 2, SM_L = 4,
  805.                 SM_GEQ = 3, SM_LEQ = 5 } SMCOND;
  806.  
  807. #define SM_BOF    NULL, SM_GEQ
  808. #define SM_EOF    NULL, SM_LEQ
  809.  
  810. typedef enum { SM_char, SM_int, SM_long, SM_short, SM_float, 
  811.                 SM_double, SM_string } SMDATATYPE;
  812. #define SM_Boolean SM_char
  813.  
  814. /* END visible to user */
  815. /* BEGIN visible to user */
  816.  
  817. typedef struct {
  818.         PID     pid;
  819.         } IID;                    /* INDEX IDENTIFIER */
  820.  
  821. #ifdef __cplusplus
  822. #ifdef PIDEQ
  823. inline operator ==(const IID& i1, const IID& i2) {
  824.         return PIDEQ(i1.pid, i2.pid);
  825.         }
  826. inline operator !=(const IID& i1, const IID& i2) {
  827.         return ! (i1 == i2);
  828.         }
  829. #endif PIDEQ
  830. #endif __cplusplus
  831.  
  832. #define PFCDEFINED
  833. #ifdef __cplusplus
  834. typedef int     (*PFC) PROTO((int kLen1, const void* kVal1, 
  835.                                     int kLen2, const void* kVal2));
  836. #else
  837. typedef int     (*PFC) PROTO((int kLen1, void* kVal1, int kLen2, void* kVal2));
  838. #endif
  839.  
  840. typedef void    (*PFK) PROTO((int kLen, char* kVal));
  841.  
  842.  
  843. /* END visible to user */
  844. /* BEGIN visible to user */
  845.  
  846. /*
  847.  *    define the transaction id
  848.  */
  849. typedef long    TID;
  850.  
  851. /*
  852.  *    define the null tid
  853.  */
  854. #define NULL_TID    (0)
  855.  
  856.  
  857. /*
  858.  * define the maximum length of opaque char string in GTID 
  859.  */
  860. #define MAXOPAQUELEN 255
  861.  
  862. /*
  863.  *    define the global transaction id
  864.  */
  865. typedef struct {
  866.     
  867.     int         length;
  868.     char         opaque[MAXOPAQUELEN];
  869.  
  870. } GTID;
  871.  
  872. /* END visible to user */
  873. /* BEGIN visible to user */
  874. #define MAX_HOSTNAME    100
  875. #define MAX_SERVERNAME  100
  876. /* END visible to user */
  877. /* BEGIN visible to user */
  878. /*
  879.  *  define the coordinator handle
  880.  */
  881. typedef struct {
  882.      TID         coordTid;
  883.     char        hostName[MAX_HOSTNAME];  /* a.b.c.d of the server's host 
  884.                             from inet_ntoa(host's inaddr) */
  885.     char        serverName[MAX_SERVERNAME];    
  886.                         /* string representation of port # */
  887.  
  888. } COORD_HANDLE;
  889. /* END visible to user */
  890. /* BEGIN visible to user */
  891. /*
  892.  * vote returned by ESM Servers
  893.  */
  894. typedef    UONE VOTE;
  895. /* END visible to user */
  896. /* BEGIN visible to user */
  897. /*
  898.  * definitions for the votes from a server to the coordinator
  899.  */
  900. #define        VOTEUNKNOWN    0
  901. #define        YESVOTE        1
  902. #define        NOVOTE        2
  903. #define        READVOTE    3
  904. /* END visible to user */
  905. /* BEGIN visible to user */
  906. #define VERSION_NUMBER "3.0"
  907. #define  SM_VERSION_3_0
  908. /* END visible to user */
  909. /* BEGIN visible to user */
  910.  
  911. /*
  912.  *    Shutdown message flags for SHUTDOWNBODY defined in msgdefs.h
  913.  */
  914. #define SHUT_TAKE_CHECKPOINT    0x1
  915. #define SHUT_DUMP_CORE            0x2
  916. #define SHUT_ABORT_TRANS        0x4
  917. #define SHUT_COMMIT_TRANS        0x8
  918. #define SHUT_CLEAN_VOLUMES        0x10
  919. #define SHUT_ABNORMAL_EXIT        0x20
  920.  
  921. /*
  922.  *    statistics message flags for STATISTICSBODY defined in msgdefs.h
  923.  */
  924. #define STAT_CLEAR                0x1
  925.  
  926. /*
  927.  *    Statistics structure returned to clients
  928.  */
  929. typedef struct _ServerStats {
  930.     int        numClients;        /* number of clients connected        */
  931.     int        numTrans;        /* number of active transactions    */
  932.     int        numVolumes;        /* number of volumes mounted        */
  933.     int        freeLogSpace;   /* approximate number of bytes of free log space */
  934.     int        chpntFreq;         /* current checkpoint frequency */
  935.     int        totalCommits;     /* counter for number of transactions committed */
  936.     int        totalAborts;    /* counter for number of transactions aborted */
  937.     int        diskReads;        /* counter for disk read operations    */
  938.     int        diskWrites;     /* counter for disk write operations*/
  939.  
  940.     int        numActiveCoordinator;    /* number of active trans for
  941.                                         which this server is the coord */
  942.     int        numPreparedParticipant;    /* number of prepared trans for 
  943.                                        which the server is a 
  944.                                        participant */
  945.  
  946.     MESSAGESTATS msgStats;  /* server's message stats */
  947.  
  948.     struct sockaddr_in     serverAddr;/* inet addr to which server listens */
  949.  
  950. } SERVERSTATS;
  951.  
  952. /* END visible to user */
  953. /* BEGIN visible to user */
  954.  
  955. /*
  956.  *  Definition of flags for buffer groups
  957.  */
  958. #define G_FREE      0x0
  959. #define G_OPEN      0x1
  960. #define G_TRANS     0x2
  961.  
  962. /* added for client operation logging - MJF */
  963. #define LOG_GROUP   0x4
  964. #define FORCE_GROUP 0x8
  965.  
  966. /* END visible to user */
  967. /* BEGIN visible to user */
  968. /* 
  969.  * Buffer replacement policies for buffer groups.
  970.  */
  971. #define BF_DEFAULT      0
  972. #define BF_LRU          1
  973. #define BF_MRU          2
  974. /* END visible to user */
  975. /* BEGIN visible to user */
  976. typedef struct UserDesc {
  977.  
  978.     char        *basePtr;       /* ptr user will use to access data     */
  979.     int            byteCount;      /* bytes accessible to user             */
  980.     int            objectSize;     /* size of object                       */
  981.     TWO         userFlags;      /* properties field of the obj header   */
  982.     TWO         type;   
  983.     TWO         flags;          /* if this descriptor is valid          */
  984.     TWO         tag;            /* tag field from obj hdr               */
  985.     OID         oid;            /* oid of object being referenced       */
  986. /* END visible to user */
  987. /* BEGIN visible to user */
  988. } USERDESC;
  989. /* END visible to user */
  990. /* BEGIN visible to user */
  991. /* Flags passed as argument to administrative funcs, such
  992.  * as sm_GetRusage(), to indicate which servers to address
  993.  */
  994. #define VOL_ALL                    0
  995. #define VOL_USED_SINCE_INIT        1
  996. #define VOL_USED_IN_TRANSACTION 2
  997. #define VOL_BY_VOLID             3
  998.  
  999. /* END visible to user */
  1000. /* BEGIN visible to user */
  1001.  
  1002. typedef struct struct_scan_desc SCANDESC;
  1003.  
  1004. /* END visible to user */
  1005. /* BEGIN visible to user */
  1006.  
  1007. /*
  1008.  *    types of allowed scans
  1009.  */
  1010. #define LOGICAL_SCAN    0x1
  1011. #define PHYSICAL_SCAN    0x2
  1012.  
  1013. /* END visible to user */
  1014. /* BEGIN visible to user */
  1015.  
  1016. typedef struct struct_load_desc LOADDESC;
  1017.  
  1018. /* END visible to user */
  1019. /* BEGIN visible to user */
  1020.  
  1021. /*
  1022.  *    types of allowed loads
  1023.  */
  1024. #define LOGICAL_LOAD    0x1
  1025. #define PHYSICAL_LOAD    0x2
  1026.  
  1027. /* END visible to user */
  1028. /* BEGIN visible to user */
  1029.  
  1030. /*
  1031.  *    define flags for file creation parameters
  1032.  */
  1033. #define LOGICAL_ORDER    0x1
  1034.  
  1035. /* END visible to user */
  1036. /* BEGIN visible to user */
  1037.  
  1038. /*
  1039.  *    Define types of storage manager errors
  1040.  */
  1041. #define TYPE_USER        0
  1042. #define TYPE_LOG        1
  1043. #define TYPE_WARNING    2
  1044. #define TYPE_SYS        3
  1045. #define TYPE_FATAL        4 /* kill server and dump core */
  1046. #define TYPE_CRASH        5
  1047.     /* 
  1048.      *    TYPE_CRASH is used for errors which the storage manager 
  1049.      *     should be able to "handle" but are not dealt with at
  1050.      *     this time
  1051.      */
  1052. #define TYPE_STOP        6 
  1053. #define TYPE_QUIET        7 /* like TYPE_STOP but no message given */
  1054.     
  1055.  
  1056. /*
  1057.  *    Macro to encode error code as a base number in the upper 16 bits
  1058.  *    and an error number in the lower 16 bits
  1059.  */
  1060. #define    SM_ERR_ENCODE(_base, _number)                    \
  1061.     ( ((_base) << 16) + (_number) )
  1062.  
  1063.  
  1064. /*
  1065.  *    Macro to decode the error number
  1066.  */
  1067. #define    SM_ERR_DECODE(_code)                    \
  1068.     (  (_code) & (0x0000FFFF ) )
  1069.  
  1070. /*
  1071.  *    Macro to decode the base number for the error
  1072.  */
  1073. #define    SM_ERR_BASE_DECODE(_code)                    \
  1074.     (  (_code) >> 16 )
  1075.  
  1076.  
  1077. #define UNIX_ERROR_BASE            0
  1078. #define GENERAL_ERROR_BASE        1
  1079. #define SM_ERROR_BASE            2
  1080. #define BF_ERROR_BASE            3
  1081. #define LG_ERROR_BASE            4
  1082. #define EH_ERROR_BASE            5
  1083. #define FI_ERROR_BASE            6
  1084. #define IO_ERROR_BASE            7
  1085. #define MSG_ERROR_BASE            8
  1086. #define THREAD_ERROR_BASE        9
  1087. #define BM_ERROR_BASE            10
  1088. #define TRANS_ERROR_BASE        11
  1089. #define LOCK_ERROR_BASE            12
  1090. #define LOG_ERROR_BASE            13
  1091. #define RESOURCE_ERROR_BASE        14
  1092. #define RECOVER_ERROR_BASE        15
  1093. #define IM_ERROR_BASE            16
  1094. #define OPT_ERROR_BASE            17
  1095. #define DISTR_ERROR_BASE        18
  1096. #define MAX_ERROR_BASE            19     /* always last */
  1097.  
  1098. /*
  1099.  *    The unix errors are defined in /usr/include/errno.h
  1100.  */
  1101. #define MAX_UNIX_ERROR            0x0fffffff /* unknown */
  1102.  
  1103. /*
  1104.  *    define the general errors
  1105.  */
  1106. #define esmINTERNAL                SM_ERR_ENCODE(GENERAL_ERROR_BASE, 1)
  1107. #define esmASSERT                SM_ERR_ENCODE(GENERAL_ERROR_BASE, 2)
  1108. #define esmMALLOCFAILED            SM_ERR_ENCODE(GENERAL_ERROR_BASE, 3)
  1109. #define esmSERVERDIED            SM_ERR_ENCODE(GENERAL_ERROR_BASE, 4)
  1110. #define esmNOTIMPLEMENTED        SM_ERR_ENCODE(GENERAL_ERROR_BASE, 5)
  1111. #define esmUNIXSIGNAL            SM_ERR_ENCODE(GENERAL_ERROR_BASE, 6)
  1112. #define esmPOOLEMPTY            SM_ERR_ENCODE(GENERAL_ERROR_BASE, 7)
  1113. #define MAX_GENERAL_ERROR        8 /* adjust as errors added/removed */
  1114.  
  1115. /*
  1116.  *    define the sm layer errors
  1117.  */
  1118. #define esmBADOID                SM_ERR_ENCODE(SM_ERROR_BASE, 1)
  1119. #define esmBADSTART                SM_ERR_ENCODE(SM_ERROR_BASE, 2)
  1120. #define esmNOFREEUSERDESC        SM_ERR_ENCODE(SM_ERROR_BASE, 3)
  1121. #define esmBADUSERDESC            SM_ERR_ENCODE(SM_ERROR_BASE, 4)
  1122. #define esmBADPARAMS            SM_ERR_ENCODE(SM_ERROR_BASE, 5)
  1123. #define esmBADGROUP                SM_ERR_ENCODE(SM_ERROR_BASE, 6)
  1124. #define esmBADLENGTH            SM_ERR_ENCODE(SM_ERROR_BASE, 7)
  1125. #define esmROOTNAMETOOLONG        SM_ERR_ENCODE(SM_ERROR_BASE, 8)
  1126. #define esmNOFREESCANDESC        SM_ERR_ENCODE(SM_ERROR_BASE, 9)
  1127. #define esmENDOFOBJECT            SM_ERR_ENCODE(SM_ERROR_BASE, 10)
  1128. #define esmBADSLOTTEDMAGIC        SM_ERR_ENCODE(SM_ERROR_BASE, 11)
  1129. #define esmBADOBJECTMAGIC        SM_ERR_ENCODE(SM_ERROR_BASE, 12)
  1130. #define esmBADOBJECTFLAGS        SM_ERR_ENCODE(SM_ERROR_BASE, 13)
  1131. #define esmNOFREELOADDESC        SM_ERR_ENCODE(SM_ERROR_BASE, 14)
  1132. #define esmHISTORYGRAPHOID        SM_ERR_ENCODE(SM_ERROR_BASE, 15)
  1133. #define esmNOTVERSIONED            SM_ERR_ENCODE(SM_ERROR_BASE, 16) /* obj not a version */
  1134. #define esmNOTFROZEN            SM_ERR_ENCODE(SM_ERROR_BASE, 17) /* obj not frozen */
  1135. #define esmFROZEN                SM_ERR_ENCODE(SM_ERROR_BASE, 18) /* obj is frozen */
  1136. #define esmVHGTOOLARGE            SM_ERR_ENCODE(SM_ERROR_BASE, 19) 
  1137. #define MAX_SM_ERROR            20 /* adjust as errors added/removed */
  1138.  
  1139.  
  1140. /*
  1141.  *    define the bf related error
  1142.  */
  1143. #define esmCANTSWAP                SM_ERR_ENCODE(BF_ERROR_BASE, 1)
  1144. #define esmFIXEDPAGES            SM_ERR_ENCODE(BF_ERROR_BASE, 2)
  1145. #define esmNOFREEPAGEHASH        SM_ERR_ENCODE(BF_ERROR_BASE, 3)
  1146. #define esmNOUNRESERVED            SM_ERR_ENCODE(BF_ERROR_BASE, 4)
  1147. #define esmNOFREEGROUPS            SM_ERR_ENCODE(BF_ERROR_BASE, 5)
  1148. #define esmBADREPLACEPOLICY        SM_ERR_ENCODE(BF_ERROR_BASE, 6)
  1149. #define esmPAGEGONE                SM_ERR_ENCODE(BF_ERROR_BASE, 7)
  1150. #define esmNOBUFSPACE            SM_ERR_ENCODE(BF_ERROR_BASE, 8)
  1151. #define esmREQUESTTOOBIG        SM_ERR_ENCODE(BF_ERROR_BASE, 9)
  1152. #define esmGROUPGONE            SM_ERR_ENCODE(BF_ERROR_BASE, 10)
  1153. #define esmNOSHMSPACE            SM_ERR_ENCODE(BF_ERROR_BASE, 11)
  1154. #define MAX_BF_ERROR            12 /* adjust as errors added/removed */
  1155.  
  1156.  
  1157. /*
  1158.  *    define the large object related errors
  1159.  */
  1160. #define esmBADRANGE                SM_ERR_ENCODE(LG_ERROR_BASE, 1)
  1161. #define esmNOFREELGNODELIST        SM_ERR_ENCODE(LG_ERROR_BASE, 2)
  1162. #define MAX_LG_ERROR            3 /* adjust as errors added/removed */
  1163.  
  1164. /*
  1165.  *    define the error handler related errors
  1166.  */
  1167. #define MAX_EH_ERROR            0 /* adjust as errors added/removed */
  1168.  
  1169. /*
  1170.  *    define the file layer errors
  1171.  */
  1172. #define esmEMPTYFILE            SM_ERR_ENCODE(FI_ERROR_BASE, 1)
  1173. #define esmBADNEARTYPE            SM_ERR_ENCODE(FI_ERROR_BASE, 2)
  1174. #define esmBADFILEPAGEMAGIC        SM_ERR_ENCODE(FI_ERROR_BASE, 3)
  1175. #define esmAFTERLASTPID            SM_ERR_ENCODE(FI_ERROR_BASE, 4)
  1176. #define esmBEFOREFIRSTPID        SM_ERR_ENCODE(FI_ERROR_BASE, 5)
  1177. #define esmFILESTACKOVERFLOW    SM_ERR_ENCODE(FI_ERROR_BASE, 6)
  1178. #define esmFILEPAGENOTFOUND        SM_ERR_ENCODE(FI_ERROR_BASE, 7)
  1179. #define esmNOFREEFILESTACK        SM_ERR_ENCODE(FI_ERROR_BASE, 8)
  1180. #define esmPAGEEXISTS            SM_ERR_ENCODE(FI_ERROR_BASE, 9)
  1181. #define esmPAGEMARKED            SM_ERR_ENCODE(FI_ERROR_BASE, 10)
  1182. #define esmBADFID                SM_ERR_ENCODE(FI_ERROR_BASE, 11)
  1183. #define esmNOFREEFIDHASH        SM_ERR_ENCODE(FI_ERROR_BASE, 12)
  1184. #define esmFILENOTLOGICAL        SM_ERR_ENCODE(FI_ERROR_BASE, 13)
  1185. #define esmBADPAGESIZE            SM_ERR_ENCODE(FI_ERROR_BASE, 14)
  1186. #define esmBADFILEHEADERMAGIC    SM_ERR_ENCODE(FI_ERROR_BASE, 15)
  1187. #define esmNOFREEOPENFILE        SM_ERR_ENCODE(FI_ERROR_BASE, 16)
  1188. #define MAX_FILE_ERROR            17 /* adjust as errors added/removed */
  1189.  
  1190.  
  1191. /*
  1192.  *    define the io related errors
  1193.  */
  1194. #define esmBADVOLHEADER            SM_ERR_ENCODE(IO_ERROR_BASE, 1)
  1195. #define esmDUPVOLID                SM_ERR_ENCODE(IO_ERROR_BASE, 2)
  1196. #define esmDISKPROCDIED            SM_ERR_ENCODE(IO_ERROR_BASE, 3)
  1197. #define esmBADVOLID                SM_ERR_ENCODE(IO_ERROR_BASE, 4)
  1198. #define esmDUPVOLNAME            SM_ERR_ENCODE(IO_ERROR_BASE, 5)
  1199. #define esmFRAGMENTED            SM_ERR_ENCODE(IO_ERROR_BASE, 6)
  1200. #define esmDISKFULL                SM_ERR_ENCODE(IO_ERROR_BASE, 7)
  1201. #define esmDISKMOUNTED            SM_ERR_ENCODE(IO_ERROR_BASE, 8)
  1202. #define esmBADROOTNAME            SM_ERR_ENCODE(IO_ERROR_BASE, 9)
  1203. #define esmROOTTABLEFULL        SM_ERR_ENCODE(IO_ERROR_BASE, 10)
  1204. #define esmNOVOLINFO            SM_ERR_ENCODE(IO_ERROR_BASE, 11)
  1205. #define esmNOFREECONTEXT        SM_ERR_ENCODE(IO_ERROR_BASE, 12)
  1206. #define esmBADPID                SM_ERR_ENCODE(IO_ERROR_BASE, 13)
  1207. #define esmSERVPROCDIED            SM_ERR_ENCODE(IO_ERROR_BASE, 14)
  1208. #define esmNOSUCHVOLUME            SM_ERR_ENCODE(IO_ERROR_BASE, 15)
  1209. #define esmMOUNTTABLEFULL        SM_ERR_ENCODE(IO_ERROR_BASE, 16)
  1210.  
  1211. #define MAX_IO_ERROR            17 /* adjust as errors added/removed */
  1212.  
  1213.  
  1214. /*
  1215.  *    define the message related errors
  1216.  */
  1217. #define esmPROTOCOLVERSION        SM_ERR_ENCODE(MSG_ERROR_BASE, 1)
  1218. #define esmBADMESSAGENUMBER        SM_ERR_ENCODE(MSG_ERROR_BASE, 2)
  1219. #define esmBADMESSAGEMAGIC        SM_ERR_ENCODE(MSG_ERROR_BASE, 3)
  1220. #define esmALREADYCONNECTED        SM_ERR_ENCODE(MSG_ERROR_BASE, 4)
  1221. #define esmNOTCONNECTED            SM_ERR_ENCODE(MSG_ERROR_BASE, 5)
  1222. #define esmNOFREETIMERS            SM_ERR_ENCODE(MSG_ERROR_BASE, 6)
  1223. #define esmUNKNOWNHOSTNAME      SM_ERR_ENCODE(MSG_ERROR_BASE, 7)
  1224. #define esmCONFIGMISMATCH        SM_ERR_ENCODE(MSG_ERROR_BASE, 8)
  1225. #define esmBADFAMILY            SM_ERR_ENCODE(MSG_ERROR_BASE, 9)
  1226. #define MAX_MSG_ERROR          10 /* adjust as errors added/removed */
  1227.  
  1228.  
  1229. /*
  1230.  *    define the thread related errors
  1231.  */
  1232. #define esmNOFREETHREAD            SM_ERR_ENCODE(THREAD_ERROR_BASE, 1)
  1233. #define MAX_THREAD_ERROR        2 /* adjust as errors added/removed */
  1234.  
  1235.  
  1236. /*
  1237.  *    define the bitmap related error
  1238.  */
  1239. #define esmNOFREEPAGECONTEXT    SM_ERR_ENCODE(BM_ERROR_BASE, 1)
  1240. #define esmTOOMANYBITS            SM_ERR_ENCODE(BM_ERROR_BASE, 2)
  1241. #define MAX_BM_ERROR            3 /* adjust as errors added/removed */
  1242.  
  1243.  
  1244. /*
  1245.  *    define the transaction related errors
  1246.  */
  1247. #define esmNOFREETRANSREC        SM_ERR_ENCODE(TRANS_ERROR_BASE, 1)
  1248. #define esmTRANSDISABLED        SM_ERR_ENCODE(TRANS_ERROR_BASE, 2)
  1249. #define esmBADTRANSID            SM_ERR_ENCODE(TRANS_ERROR_BASE, 3)
  1250. #define esmNOTTRANSMASTER        SM_ERR_ENCODE(TRANS_ERROR_BASE, 4)
  1251. #define esmTRANSABORTED            SM_ERR_ENCODE(TRANS_ERROR_BASE, 5)
  1252. #define esmTRANSCOMMITTED        SM_ERR_ENCODE(TRANS_ERROR_BASE, 6)
  1253. #define esmNOFREETRANSVOLREC    SM_ERR_ENCODE(TRANS_ERROR_BASE, 7)
  1254. #define esmTRANSINPROGRESS        SM_ERR_ENCODE(TRANS_ERROR_BASE, 8)
  1255. #define esmNOACTIVETRANS        SM_ERR_ENCODE(TRANS_ERROR_BASE, 9)
  1256. #define esmCLIENTREQUEST        SM_ERR_ENCODE(TRANS_ERROR_BASE, 10)
  1257. #define MAX_TRANS_ERROR            11 /* adjust as errors added/removed */
  1258.  
  1259.  
  1260. /*
  1261.  *    define the locking related errors
  1262.  */
  1263. #define esmBADLOCKTABLESIZE        SM_ERR_ENCODE(LOCK_ERROR_BASE, 1)
  1264. #define esmBADLOCKMODE            SM_ERR_ENCODE(LOCK_ERROR_BASE, 2)
  1265. #define esmNOFREELOCKHEADER        SM_ERR_ENCODE(LOCK_ERROR_BASE, 3)
  1266. #define esmNOFREELOCKENTRY        SM_ERR_ENCODE(LOCK_ERROR_BASE, 4)
  1267. #define esmNOFREELOCKCLASSREC    SM_ERR_ENCODE(LOCK_ERROR_BASE, 5)
  1268. #define esmNOFREELOCKCLASS        SM_ERR_ENCODE(LOCK_ERROR_BASE, 6)
  1269. #define esmBADLOCKCLASS            SM_ERR_ENCODE(LOCK_ERROR_BASE, 7)
  1270. #define esmLOCKBUSY                SM_ERR_ENCODE(LOCK_ERROR_BASE, 8)
  1271. #define esmLOCKCAUSEDDEADLOCK    SM_ERR_ENCODE(LOCK_ERROR_BASE, 9)
  1272. #define esmNOSUCHLOCK            SM_ERR_ENCODE(LOCK_ERROR_BASE, 10)
  1273. #define esmWAITEREXISTS            SM_ERR_ENCODE(LOCK_ERROR_BASE, 11)
  1274. #define esmPHANTOMDEADLOCK        SM_ERR_ENCODE(LOCK_ERROR_BASE, 12)
  1275. #define esmCAUSEDPHANTOMDEADLOCK SM_ERR_ENCODE(LOCK_ERROR_BASE, 13)
  1276. #define esmLOCKPREEMPTED         SM_ERR_ENCODE(LOCK_ERROR_BASE, 14)
  1277. #define MAX_LOCK_ERROR            15 /* adjust as errors added/removed */
  1278.  
  1279.  
  1280. /*
  1281.  *    define the logging related errors
  1282.  */
  1283. #define esmLOGDISABLED            SM_ERR_ENCODE(LOG_ERROR_BASE, 1)
  1284. #define esmLOGWRAPPED            SM_ERR_ENCODE(LOG_ERROR_BASE, 2)
  1285. #define esmNOFREELOGSPACE        SM_ERR_ENCODE(LOG_ERROR_BASE, 3)
  1286. #define esmLOGRECORDTOOBIG        SM_ERR_ENCODE(LOG_ERROR_BASE, 4)
  1287. #define esmBADLOGPAGEHEADER        SM_ERR_ENCODE(LOG_ERROR_BASE, 5)
  1288. #define esmBADLOGRECORDHEADER    SM_ERR_ENCODE(LOG_ERROR_BASE, 6)
  1289. #define esmBADLOGVOLUME            SM_ERR_ENCODE(LOG_ERROR_BASE, 7)
  1290. #define esmMOUNTLSNTOOHIGH        SM_ERR_ENCODE(LOG_ERROR_BASE, 8)
  1291. #define esmLOGTOOSMALL            SM_ERR_ENCODE(LOG_ERROR_BASE, 9)
  1292. #define esmLOGGINGOFF            SM_ERR_ENCODE(LOG_ERROR_BASE, 10)
  1293. #define MAX_LOG_ERROR            11 /* adjust as errors added/removed */
  1294.  
  1295.  
  1296. /*
  1297.  *    define the resource related errors
  1298.  */
  1299. #define esmBADRESOURCE            SM_ERR_ENCODE(RESOURCE_ERROR_BASE, 1)
  1300. #define MAX_RESOURCE_ERROR        2 /* adjust as errors added/removed */
  1301.  
  1302.  
  1303. /*
  1304.  *    define the recovery related errors
  1305.  */
  1306. #define    esmCANNOTRECOVER        SM_ERR_ENCODE(RECOVER_ERROR_BASE, 1)
  1307. #define MAX_RECOVER_ERROR        2 /* adjust as errors added/removed */
  1308.  
  1309.  
  1310. /*
  1311.  *    define the Index Manager related errors
  1312.  */
  1313. #define esmKEYNOTFOUND            SM_ERR_ENCODE(IM_ERROR_BASE, 1)
  1314. #define esmKEYALREADYEXISTS        SM_ERR_ENCODE(IM_ERROR_BASE, 2)
  1315. #define esmDUPLICATEKEYPID        SM_ERR_ENCODE(IM_ERROR_BASE, 3)
  1316. #define esmKEYTOOLONG            SM_ERR_ENCODE(IM_ERROR_BASE, 4)
  1317. #define esmMAXKEYLENEXCEEDED    SM_ERR_ENCODE(IM_ERROR_BASE, 5)
  1318. #define esmOIDNOTFOUND            SM_ERR_ENCODE(IM_ERROR_BASE, 6)
  1319. #define esmOIDEXISTS            SM_ERR_ENCODE(IM_ERROR_BASE, 7)
  1320. #define esmINVALIDDIRECTION        SM_ERR_ENCODE(IM_ERROR_BASE, 8)
  1321. #define esmSCANEXHAUST            SM_ERR_ENCODE(IM_ERROR_BASE, 9)
  1322. #define esmINVALIDCURSOR        SM_ERR_ENCODE(IM_ERROR_BASE, 10)
  1323. #define esmINVALIDCOND            SM_ERR_ENCODE(IM_ERROR_BASE, 11)
  1324. #define esmCONFLICTCOND            SM_ERR_ENCODE(IM_ERROR_BASE, 12)
  1325. #define esmBULKLOADING          SM_ERR_ENCODE(IM_ERROR_BASE, 13)
  1326. #define esmINDEXNOTEMPTY        SM_ERR_ENCODE(IM_ERROR_BASE, 14)
  1327. #define esmNEEDTEMPVOL            SM_ERR_ENCODE(IM_ERROR_BASE, 15)
  1328. #define esmWRONGNDXTYPE            SM_ERR_ENCODE(IM_ERROR_BASE, 16)
  1329. #define esmWRONGHASHLOAD        SM_ERR_ENCODE(IM_ERROR_BASE, 17)
  1330. #define MAX_IM_ERROR            18 /* adjust as errors added/removed */
  1331.  
  1332. /*
  1333.  *    define the option processing related errors
  1334.  */
  1335. #define esmBADOPTION            SM_ERR_ENCODE(OPT_ERROR_BASE, 1)
  1336. #define esmOPTIONSYNTAX            SM_ERR_ENCODE(OPT_ERROR_BASE, 2)
  1337. #define esmOPTIONNOTUNIQUE        SM_ERR_ENCODE(OPT_ERROR_BASE, 3)
  1338. #define esmOPTIONNOTSET            SM_ERR_ENCODE(OPT_ERROR_BASE, 4)
  1339. #define esmBADOPTIONCLASS        SM_ERR_ENCODE(OPT_ERROR_BASE, 5)
  1340. #define esmBADOPTIONVALUE        SM_ERR_ENCODE(OPT_ERROR_BASE, 6)
  1341. #define esmBUFPAGESNOTSET        SM_ERR_ENCODE(OPT_ERROR_BASE, 7)
  1342. #define MAX_OPT_ERROR            8 /* adjust as errors added/removed */
  1343.  
  1344. /*
  1345.  *    define the distributed transaction related errors
  1346.  */
  1347. #define esmTRANSNOTPREPARED        SM_ERR_ENCODE(DISTR_ERROR_BASE, 1)
  1348. #define esmBADCOMMAND            SM_ERR_ENCODE(DISTR_ERROR_BASE, 2)
  1349. #define esmNOFREEGTIDREC        SM_ERR_ENCODE(DISTR_ERROR_BASE, 3)
  1350. #define esmTOOMANYSERVERS        SM_ERR_ENCODE(DISTR_ERROR_BASE, 4)
  1351. #define esmNOFREESERVERTIDINFO    SM_ERR_ENCODE(DISTR_ERROR_BASE, 5)
  1352. #define esmBADHANDLE            SM_ERR_ENCODE(DISTR_ERROR_BASE, 6)
  1353. #define esmWOULDBLOCK            SM_ERR_ENCODE(DISTR_ERROR_BASE, 7)
  1354. #define esmBADVOTE                SM_ERR_ENCODE(DISTR_ERROR_BASE, 8)
  1355. #define esmBADSTATE                SM_ERR_ENCODE(DISTR_ERROR_BASE, 9)
  1356. #define esmCOORDUNKNOWN            SM_ERR_ENCODE(DISTR_ERROR_BASE, 10)
  1357. #define esmTRANSPREPARED        SM_ERR_ENCODE(DISTR_ERROR_BASE, 11)
  1358. #define esmTRANSIN2PC            SM_ERR_ENCODE(DISTR_ERROR_BASE, 12)
  1359. #define esmTRANSNOTIN2PC        SM_ERR_ENCODE(DISTR_ERROR_BASE, 13)
  1360. #define MAX_DISTR_ERROR            14 /* adjust as errors added/removed */
  1361.  
  1362. /*
  1363.  *    Define error for handling macros
  1364.  */
  1365. #define SM_ERROR(type, code)                    \
  1366.     SM_Error((type), (code), __FILE__, __LINE__)
  1367. /* END visible to user */
  1368. /* BEGIN visible to user */
  1369. #define SM_TRANSABORTED(type, reason)    \
  1370.     sm_reason = reason;\
  1371.     SM_Error((type), esmTRANSABORTED, __FILE__, __LINE__)
  1372. /* END visible to user */
  1373. /* BEGIN visible to user */
  1374. /*
  1375.  *    define flags for opening a buffer group
  1376.  */
  1377. #define TRANS_GROUP        0x1
  1378. /* END visible to user */
  1379. /* BEGIN visible to user */
  1380.  
  1381. /*
  1382.  *    the typedef for a lock mode.  The size of this
  1383.  *    definition defines the number of lock modes that
  1384.  *    can be allocated
  1385.  */
  1386. typedef UONE    LOCKMODE;
  1387.  
  1388.  
  1389. /*
  1390.  *    define the specific information that relates to our type of lock modes
  1391.  */
  1392. #define NUM_LOCK_MODES        6
  1393.  
  1394. /* END visible to user */
  1395. /* BEGIN visible to user */
  1396.  
  1397. /*
  1398.  *    define the lock modes
  1399.  */
  1400. #define NL    0
  1401. #define IS    1
  1402. #define IX    2
  1403. #define SH    3
  1404. #define SIX    4
  1405. #define EX    5
  1406.  
  1407. /* END visible to user */
  1408. /* BEGIN visible to user */
  1409.  
  1410. /*
  1411.  *    Definition of tracing areas
  1412.  */
  1413. #define TR_DEBUG        0x1
  1414. #define TR_BF            0x2
  1415. #define TR_LIST            0x4
  1416. #define TR_FI            0x8
  1417.  
  1418. #define TR_SM            0x10
  1419. #define TR_LG            0x20
  1420. #define TR_EH            0x40
  1421. #define TR_IO            0x80
  1422.  
  1423. #define TR_TEST            0x100
  1424. #define TR_THREAD        0x200
  1425. #define TR_LATCH        0x400
  1426. #define TR_SEM            0x800
  1427.  
  1428. #define TR_INIT            0x1000
  1429. #define TR_DISK            0x2000
  1430. #define TR_MSG            0x4000
  1431. #define TR_DISKRW        0x8000
  1432.  
  1433. #define TR_ADMIN        0x10000
  1434. #define TR_CL            0x20000
  1435. #define TR_BITMAP        0x40000
  1436. #define TR_TRANS        0x80000
  1437.  
  1438. #define TR_LOCK            0x100000
  1439. #define TR_LOG            0x200000
  1440. #define TR_RECOVER        0x400000
  1441. #define TR_ACCESS        0x800000
  1442.  
  1443. #define TR_SEQ            0x1000000
  1444. #define TR_VERSION        0x2000000
  1445. #define TR_VHGLIST        0x4000000 /* version history graph list funcs */
  1446. #define TR_SHM            0x8000000 /* shared memory functions         */
  1447.  
  1448. #define TR_DISTR        0x10000000    /* for distr trans */
  1449. #define TR_MR            0x20000000    /* media recovery */
  1450.  
  1451.  
  1452. /*
  1453.  *    definition of trace flags
  1454.  */
  1455. typedef unsigned long TRACEFLAGS;
  1456.  
  1457.  
  1458. /*
  1459.  *    define a trace array for levels
  1460.  */
  1461. typedef struct    {
  1462.  
  1463.     unsigned char    level[32];
  1464.  
  1465. } TRACELEVEL;
  1466.  
  1467.  
  1468. /*
  1469.  *    put in the extern declaration
  1470.  */
  1471. extern TRACEFLAGS    TraceFlags;
  1472. extern char            *TraceName;
  1473. extern TRACELEVEL    TraceLevel;
  1474.  
  1475.  
  1476. /*
  1477.  *    define the tracing levels
  1478.  */
  1479. #define TR_LEVEL_0        (0)
  1480. #define TR_LEVEL_1        (1)
  1481. #define TR_LEVEL_2        (2)
  1482. #define TR_LEVEL_3        (3)
  1483.  
  1484.  
  1485. /*
  1486.  *    define function prototypes
  1487.  */
  1488. #ifdef __cplusplus
  1489. extern "C" {
  1490. #endif
  1491.  
  1492. extern int    checkTraceLevel PROTO((TRACEFLAGS, int));
  1493.  
  1494. #ifdef __cplusplus
  1495. }
  1496. #endif
  1497.  
  1498. /* END visible to user */
  1499. /* BEGIN visible to user */
  1500.  
  1501. /*
  1502.  *    Macros for tracing
  1503.  *
  1504.  *    Depend on the global variable Trace for information
  1505.  */
  1506.  
  1507. #ifdef DEBUG
  1508.  
  1509. #define TRACING        ENABLED
  1510.  
  1511. #else
  1512.  
  1513. #define TRACING        DISABLED
  1514.  
  1515. #endif
  1516.  
  1517.  
  1518. #if TRACING IS_ENABLED
  1519.  
  1520.  
  1521. #define TRACE(_Area, _Level) (                                                    \
  1522.                                                                                 \
  1523.     (((_Area) & TraceFlags) && (checkTraceLevel((_Area), _Level))) ? (            \
  1524.         printf("%s file: %-22s  line: %4d\n", TraceName, __FILE__, __LINE__),    \
  1525.         fflush(stdout)                                                            \
  1526.     ) : (TraceFlags)                                                            \
  1527. )
  1528.  
  1529.  
  1530. #define TRPRINT(_Area, _Level, _Message) (                                        \
  1531.                                                                                 \
  1532.     (((_Area) & TraceFlags) && (checkTraceLevel((_Area), _Level))) ? (            \
  1533.         printf("%s file: %-22s  line: %4d  ", TraceName, __FILE__, __LINE__),    \
  1534.         printf _Message,                                                        \
  1535.         printf("\n"),                                                            \
  1536.         fflush(stdout)                                                            \
  1537.     ) : (TraceFlags)                                                            \
  1538. )
  1539.  
  1540.  
  1541. #else
  1542.  
  1543.  
  1544. #define TRACE(_Area, _Level)
  1545.  
  1546. #define TRPRINT(_Area, _Message, _Level)
  1547.  
  1548.  
  1549. #endif
  1550.  
  1551. /* END visible to user */
  1552. /* BEGIN visible to user */
  1553. extern int            sm_errno;
  1554. extern int            sm_reason;    /* reason a transaction was aborted */
  1555. extern FILE            *sm_ErrorStream;
  1556.  
  1557. /*
  1558.  *    Default locking modes for files and pages.  
  1559.  *    Users can set these as desired.
  1560.  */
  1561. extern LOCKMODE        sm_DefaultPageLock;
  1562. extern LOCKMODE        sm_DefaultFileLock;
  1563.  
  1564. /* END visible to user */
  1565. /* BEGIN visible to user */
  1566.  
  1567. #define SM_MAXKEYLEN            1024    /* max length of index key */
  1568.  
  1569. #define SM_MAXOPTCLASS            10        /* max # of option classification levels */
  1570.  
  1571. /* END visible to user */
  1572. /* BEGIN visible to user */
  1573.  
  1574. /*
  1575.  * Logging level flags
  1576.  */
  1577. #define    LOG_NONE    0x0
  1578. #define    LOG_SPACE    0x1
  1579. #define    LOG_DATA    0x2
  1580. #define LOG_ALL        (LOG_DATA | LOG_SPACE)
  1581.  
  1582. /* END visible to user */
  1583. /* BEGIN visible to user */
  1584.  
  1585. /* use as a parameter on object reads to specify entire object */
  1586. #define READ_ALL -1
  1587.  
  1588. /* use as a parameter on object delete to specify rest of object */
  1589. #define DELETE_ALL -1
  1590.  
  1591.  
  1592. /*
  1593.  *    Macros to set invalid (null) object, index, file, transaction,
  1594.  *    cursor, and buffer group ID's
  1595.  */
  1596. #define INVALIDATE_OID(_oid)    ((_oid).diskAddr.volid = 0)
  1597. #define OID_IS_INVALID(_oid)    ((_oid).diskAddr.volid == 0)
  1598. #define INVALIDATE_IID(_iid)    ((_iid).pid.volid = 0)
  1599. #define IID_IS_INVALID(_iid)    ((_iid).pid.volid == 0)
  1600. #define INVALIDATE_FID(_fid)    ((_fid).pid.volid = 0)
  1601. #define FID_IS_INVALID(_fid)    ((_fid).pid.volid == 0)
  1602. #define INVALIDATE_TID(_tid)    ((_tid) = 0)
  1603. #define TID_IS_INVALID(_tid)    ((_tid) < 1)
  1604. #define INVALIDATE_BUFGROUP(_buf)    ((_buf) = -1)
  1605. #define BUFGROUP_IS_INVALID(_buf)    ((_buf) < 0)
  1606. #define INVALIDATE_CURSOR(_cur)    (INVALIDATE_BUFGROUP((_cur).groupIndex))
  1607. #define CURSOR_IS_INVALID(_cur) (BUFGROUP_IS_INVALID((_cur).groupIndex))
  1608. #define INVALIDATE_VOLID(_volid)  (_volid = 0)
  1609. #define VOLID_IS_INVALID(_volid)  (_volid == 0)
  1610.  
  1611.  
  1612. /*
  1613.  *    Globals required for transaction macros    
  1614.  */
  1615. extern jmp_buf    sm_TransJmpBuf;
  1616. extern int        *sm_TransReturnCode;                    
  1617.  
  1618.  
  1619. #define SM_BEGIN_TRANSACTION(_tid, _retCodeVariable)                \
  1620.     do{                                                        \
  1621.         sm_TransReturnCode = &(_retCodeVariable);            \
  1622.         *sm_TransReturnCode = esmNOERROR;                    \
  1623.         if (sm_BeginTransaction((_tid))  != esmNOERROR) {   \
  1624.             *sm_TransReturnCode = sm_errno;                    \
  1625.             break;                                            \
  1626.         }                                                    \
  1627.         if (setjmp(sm_TransJmpBuf) != 0) {                    \
  1628.             sm_AbortTransaction(*(_tid));        \
  1629.             break;                                            \
  1630.         }    
  1631.  
  1632. #define SM_COMMIT_TRANSACTION(_tid)                            \
  1633.     } while (0);                                            \
  1634.     if (*sm_TransReturnCode == esmNOERROR) {                \
  1635.         if (sm_CommitTransaction((_tid)) != esmNOERROR) {    \
  1636.             *sm_TransReturnCode = sm_errno;                    \
  1637.             sm_AbortTransaction((_tid));        \
  1638.         } else {                                            \
  1639.             *sm_TransReturnCode = esmNOERROR;                \
  1640.         }                                                    \
  1641.     }
  1642.  
  1643. #define SM_ABORT_TRANSACTION(_retCode)                        \
  1644.     {                                                        \
  1645.         *sm_TransReturnCode = (_retCode);                    \
  1646.         longjmp(sm_TransJmpBuf, 0);                            \
  1647.     }
  1648.  
  1649. /*
  1650.  *    Example use of these functions
  1651.  *
  1652.         #include <setjmp.h>
  1653.  
  1654.         SM_USE_TRANSACTION_MACROS
  1655.  
  1656.         main()
  1657.         {
  1658.             int abort;
  1659.             TID    tid;
  1660.  
  1661.             printf("outside\n");
  1662.  
  1663.             SM_BEGIN_TRANSACTION(&tid, abort)
  1664.  
  1665.                 f();
  1666.                 printf("inside\n");
  1667.             
  1668.             SM_COMMIT_TRANSACTION()
  1669.             if (abort) {
  1670.                 printf("aborted\n");
  1671.             } else {
  1672.                 printf("commited\n");
  1673.             }
  1674.         }
  1675.  
  1676.         f()
  1677.         {
  1678.             int a;
  1679.  
  1680.             printf("abort? ");
  1681.             scanf("%d", &a);
  1682.             if (a) {
  1683.                 SM_ABORT_TRANSACTION(1)
  1684.             }
  1685.         }
  1686.  
  1687.      *
  1688.      *    End of example
  1689.      */
  1690.  
  1691. /* END visible to user */
  1692. /* BEGIN visible to user */
  1693.  
  1694. typedef struct {
  1695.     BOOL valid;
  1696.     PID  rootPID;
  1697.     PID  page;
  1698.     TWO  slotNum;
  1699.     TWO  index;
  1700. } BT_CURSOR;
  1701.  
  1702.  
  1703. typedef struct {
  1704.     IID     ndx;                /* index id */
  1705.     char    b2[SM_MAXKEYLEN];   /* bound2 (must be aligned) */
  1706.     int     b2len;              /* length of bound2 */
  1707.     int     groupIndex;
  1708.     SMCOND  cond2;
  1709.     BOOL    eof;        /* TRUE if end of file reached */
  1710.     union {
  1711.     BT_CURSOR   btCursor;
  1712.     } opaque;
  1713. } SMCURSOR;
  1714.  
  1715.  
  1716. typedef struct {
  1717.     TWO     length;         /* length of the key */
  1718.     void*   valuePtr;       /* pointer to value of the key */
  1719. } KEY;
  1720.  
  1721. /* END visible to user */
  1722. /* BEGIN visible to user */
  1723.  
  1724. struct _ServerStats;
  1725.  
  1726. BEGIN_EXTERNC
  1727.  
  1728. extern int        sm_Enter2PC PROTO((TID, GTID, COORD_HANDLE * ));
  1729. extern int        sm_PrepareTransaction PROTO((TID, VOTE * ));
  1730. extern int        sm_Recover2PC PROTO((COORD_HANDLE, GTID, TID *, BOOL ));
  1731. extern int        sm_Continue2PC PROTO((TID, BOOL ));
  1732. extern int        sm_AbortTransaction PROTO((TID ));
  1733. extern int        sm_AppendToObject PROTO((int, OID *, int, void * ));
  1734. extern int        sm_BeginTransaction PROTO((TID * ));
  1735. extern int        sm_CloseBufferGroup PROTO((int ));
  1736. extern int        sm_BufferGroupInfo PROTO((int, int *, int *, int * ));
  1737. extern int        sm_CloseLoad PROTO((LOADDESC * ));
  1738. extern int        sm_CloseScan PROTO((SCANDESC * ));
  1739. extern int        sm_CommitTransaction PROTO((TID ));
  1740. extern int        sm_CreateFile PROTO((int, VOLID, FID *));
  1741. extern int        sm_DestroyFile PROTO((int, FID * ));
  1742. extern int      sm_SetLogLevel PROTO((int, int, FID[]));
  1743. extern int        sm_CreateObject PROTO((int, FID *, int, OID *, OBJHDR *, int, void *, OID * ));
  1744. extern int        sm_DeleteFromObject PROTO((int, OID *, int, int ));
  1745. extern int        sm_DestroyObject PROTO((int, OID * ));
  1746. extern char        *sm_Error PROTO((int ));
  1747. extern int        sm_GetFirstOid PROTO((int, FID *, OID *, OBJHDR *, BOOL * ));
  1748. extern int        sm_GetLastOid PROTO((int, FID *, OID *, OBJHDR *, BOOL * ));
  1749. extern int        sm_GetNextOid PROTO((int, OID *, OID *, OBJHDR *, BOOL * ));
  1750. extern int        sm_GetPreviousOid PROTO((int, OID *, OID *, OBJHDR *, BOOL * ));
  1751. extern int        sm_GetRootEntry PROTO((VOLID, char *, void *, int * ));
  1752. extern int        sm_Initialize PROTO((void));
  1753. extern int        sm_InsertInObject PROTO((int, OID *, int, int, void * ));
  1754. extern int        sm_LoadNextObject PROTO((LOADDESC *, int, void *, OID * ));
  1755. extern int        sm_OpenBufferGroup PROTO((int, int, int *, FLAGS ));
  1756. extern int        sm_OpenLoad PROTO((FID *, int, int, float, LOADDESC ** ));
  1757. extern int        sm_OpenScan PROTO((FID *, int, int, SCANDESC **, OID * ));
  1758. extern int        sm_OpenScanWithGroup PROTO((FID *, int, int, SCANDESC **, OID * ));
  1759. extern int        sm_ReadObject PROTO((int, OID *, int, int, USERDESC **));
  1760. extern int        sm_ReadObjectHeader PROTO((int, OID *, OBJHDR * ));
  1761. extern int        sm_ReleaseObject PROTO((USERDESC * ));
  1762. extern int        sm_ScanNextBytes PROTO((SCANDESC *, int ));
  1763. extern int        sm_ScanNextObject PROTO((SCANDESC *, int, int, USERDESC **, BOOL * ));
  1764. extern int        sm_SetObjectHeader PROTO((int, OID *, OBJHDR * ));
  1765. extern int        sm_SetRootEntry PROTO((VOLID, char *, void *, int ));
  1766. extern int        sm_RemoveRootEntry PROTO((VOLID, char *));
  1767. extern int        sm_ShutDown PROTO((void ));
  1768. extern int        sm_WriteObject PROTO((int, int, int, void *, USERDESC *, BOOL ));
  1769.  
  1770. extern int        sm_LockObject PROTO((int, OID *, LOCKMODE));
  1771. extern int        sm_OidToFid PROTO((int, OID *, FID *));
  1772. extern int        sm_FreezeVersion PROTO((int, OID * ));
  1773. extern int        sm_CreateVersion PROTO((int, int, OID *, OID*, OID* ));
  1774. extern char        *sm_ErrorId PROTO((int ));
  1775.  
  1776. /*
  1777.  *    Administrative functions
  1778.  */
  1779. extern int        sm_TakeCheckpoint PROTO((FLAGS, VOLID, TWO ));
  1780. extern int        sm_ChangeCheckpointFrequency PROTO((FLAGS, VOLID, int ));
  1781. extern int        sm_ShutdownServer PROTO((FLAGS, VOLID, FLAGS ));
  1782. extern int        sm_ServerStatistics PROTO((FLAGS, VOLID, int *, struct _ServerStats **, BOOL ));
  1783. extern int         sm_PrintMessageStats PROTO((FILE *const, MESSAGESTATS *const));
  1784. extern int         sm_PageCount PROTO((FID*, int*));
  1785. extern int         sm_VolumeProperties PROTO((VOLID, int *));
  1786. extern int         sm_AddServerVolume PROTO((FLAGS, VOLID, char *, char *));
  1787. extern int         sm_RemoveServerVolume PROTO((FLAGS, VOLID, VOLID)); 
  1788.  
  1789. extern int sm_CreateIndex PROTO((VOLID volume, int groupIndex, SMTYPE ndxType,
  1790.                     SMDATATYPE dataType, int maxKeyLen, 
  1791.                     int elSize, BOOL unique, IID* ndx));
  1792. extern int sm_DestroyIndex PROTO((IID* ndx, int groupIndex));
  1793. extern int sm_InsertEntry PROTO((IID* ndx, int groupIndex, KEY* key, void* elem));
  1794. extern int sm_RemoveEntry PROTO((IID* ndx, int groupIndex, KEY* key, void* elem));
  1795. extern int sm_FetchInit PROTO((IID* ndx, int groupIndex, KEY* bound1, SMCOND cond1,
  1796.                           KEY* bound2, SMCOND cond2, SMCURSOR* cursor));
  1797. extern int sm_FetchNext PROTO((SMCURSOR* cursor, KEY* retKey, 
  1798.                           void* retElem, BOOL* eof));
  1799. extern int     sm_SetLHashLoadThreshold PROTO((IID*, int, float));
  1800.  
  1801. extern int sm_BeginIndexLoad PROTO((IID* ndx, int groupIndex, int workVolume, int runSize));
  1802. extern int sm_EndIndexLoad PROTO((IID* ndx));
  1803. extern int sm_AbortIndexLoad PROTO((IID* ndx));
  1804.  
  1805.  
  1806. /*
  1807.  *    Option processing functions
  1808.  */
  1809.  
  1810. extern int        sm_SetClientOption PROTO((const char*, const void*, SMDATATYPE));
  1811. extern int        sm_GetClientOption PROTO((char*, void*));
  1812. extern int        sm_ReadConfigFile PROTO((char*, char*, char**));
  1813. extern int        sm_ParseCommandLine PROTO((int *, char**, char**));
  1814.  
  1815. extern int        sm_MountVolume PROTO((VOLID)); 
  1816. extern int        sm_DismountVolume PROTO((VOLID ));     /* needed */
  1817.  
  1818. END_EXTERNC
  1819.  
  1820. /* END visible to user */
  1821. #endif
  1822.